package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.entity.NursingProject;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @version 1.0
 * @description 说明
 * @package com.zzyl.controller
 */
@RestController
@Slf4j
@RequestMapping("/nursing_project")
@Api(tags = "护理项目管理")
public class NursingProjectController extends BaseController {

    @Resource
    private NursingProjectService nursingProjectService;


    /**
     * 护理项目分页查询
     * @param name
     * @param pageNum
     * @param pageSize
     * @param status
     * @return
     */
    @GetMapping
    @ApiOperation("护理项目分页查询")
    public ResponseResult<PageResponse<NursingProjectVo>> page(
        @ApiParam(value = "名称", required = false) String name,
        @ApiParam(value = "当前页码", required = true) Integer pageNum,
        @ApiParam(value = "每页大小", required = true) Integer pageSize,
        @ApiParam(value = "状态值，0:禁用，1:启用", required = true) Integer status
    ){
        log.info("护理项目分页查询: name={}, pageNum={}, pageSize={}, status={}", name, pageNum, pageSize, status);
        PageResponse<NursingProjectVo> pageResponse = nursingProjectService.page(name,pageNum,pageSize, status);
        return ResponseResult.success(pageResponse);
    }

    /**
     * 新增护理项目
     * @param dto
     * @return
     */
    @PostMapping
    @ApiOperation("新增护理项目")
    public ResponseResult add(@RequestBody NursingProjectDto dto){
        log.info("新增护理项目: ", dto);
        // 调用业务层新增
        nursingProjectService.add(dto);
        // 响应结果
        return success();
    }

    /**
     * 通过id查询
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    @ApiOperation("通过id查询")
    public ResponseResult<NursingProjectVo> getById(@PathVariable Long id){
        log.info("通过id查询: {}", id);
        NursingProjectVo vo = nursingProjectService.getById(id);
        return success(vo);
    }

    /**
     * 编辑护理项目
     * @param dto
     * @return
     */
    @PutMapping
    @ApiOperation("编辑护理项目")
    public ResponseResult update(@RequestBody NursingProjectDto dto){
        log.info("编辑护理项目: ", dto);
        // 调用业务层新增
        nursingProjectService.updateById(dto);
        // 响应结果
        return success();
    }

    /**
     * 启禁用护理项目
     * @param id
     * @param status
     * @return
     */
    @PutMapping("/{id}/status/{status}")
    @ApiOperation("启禁用护理项目")
    public ResponseResult enable(@PathVariable Long id,@PathVariable Integer status){
        log.info("启禁用护理项目: {},{}", id, status);
        nursingProjectService.enable(id,status);
        return success();
    }

    /**
     * 通过id删除护理项目
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    @ApiOperation("通过id删除护理项目")
    public ResponseResult deleteById(@PathVariable("id") Long id) {
        log.info("通过id删除护理项目: {}",id);
        nursingProjectService.deleteById(id);
        return ResponseResult.success();
    }

    @ApiOperation("查询所有护理项目")
    @GetMapping("/all")
    public ResponseResult <List<NursingProject>> findAll(){
        NursingProject nursingProject = new NursingProject();
        return ResponseResult.success(nursingProjectService.findAll());
    }
}
